package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.pojo.Member;
import com.itheima.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: bowen
 * @Date: 2019/7/1 15:19
 * @Description:
 */
@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {

	@Autowired
	MemberDao memberDao;
	/**
	 *  @描述：根据手机号查询会员信息
	 */
	public Member findByTelephone(String telephone) {
		return memberDao.findByTelephone(telephone);
	}

	@Override
	public void add(Member member) {
		String old = member.getPassword();
		if(old!= null){
			String newPass = MD5Utils.md5(old);
			member.setPassword(newPass);
		}
		memberDao.add(member);
	}

	@Override
	public List<Integer> findCountByMonth(List<String> months) {
		List<Integer> countList = new ArrayList();
		months.forEach(month->{
			//2019.09.31
			countList.add(memberDao.findCountByMonth(month+".31"));
		});
		return countList;
	}

	@Override
	public List getMemberGender() {
		return memberDao.getMemberGender() ;
	}

	@Override
	public List getMemberAge() {
		return memberDao.getMemberAges();
	}


}
